//
//  Views.swift
//  SwiftScienceChina
//
//  Created by 贾培军 on 2019/12/9.
//  Copyright © 2019 贾培军. All rights reserved.
//

import UIKit

public extension UIView{
    var x:CGFloat!{
        set{
            frame = CGRect(x: newValue, y: y, width: width, height: height)
        }
        get{
            return frame.origin.x
        }
    }
    var y:CGFloat!{
        set{
            frame = CGRect(x: x, y: newValue, width: width, height: height)
        }
        get{
            return frame.origin.y
        }
    }
    var width:CGFloat!{
        set{
            frame = CGRect(x: x, y: y, width: newValue, height: height)
        }
        get{
            return frame.size.width
        }
    }
    var height:CGFloat!{
        set{
            frame = CGRect(x: x, y: y, width: width, height: newValue)
        }
        get{
            return frame.size.height
        }
    }
    
    var centerX:CGFloat!{
        set{
            center = .init(x: newValue, y: center.y)
        }
        get{
            return center.x
        }
    }
    
    var centerY:CGFloat!{
        set{
            center = .init(x: center.x, y: newValue)
        }
        get{
            return center.y
        }
    }
    
    var origin:CGPoint!{
        set{
            frame = .init(origin: newValue, size: frame.size)
        }
        get{
            return frame.origin
        }
    }
    
    var maxY:CGFloat!{
        return frame.maxY
    }
    
    var maxX:CGFloat{
        return frame.maxX
        
    }
    
    func setShadowWithColor(_ color: UIColor){
           self.layer.shadowColor = color.cgColor
           self.layer.shadowRadius = 0
           self.layer.shadowOffset = CGSize(width: 0, height: 1)
           self.layer.shadowOpacity = 1
       }
    func removeAllSubviews() {
        self.subviews.forEach{$0.removeFromSuperview()}
    }
}
